home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c++
- Subject: Re: cin.get() function challenge
- Date: 29 Jan 1996 19:39:51 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan29143951@g7240065.bridge.bst.bls.com>
- References: <4eavds$d0u@news.cencom.net>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: wsenn@cencom.net's message of 26 Jan 1996 16:27:40 GMT
-
- In article <4eavds$d0u@news.cencom.net> wsenn@cencom.net (Will Senn) writes:
-
- : Some of you may recall my post of a week ago asking for help on getch() and
- : cin. The responses I received were not encouraging.
-
- Write a function in C++ not using getch() that will read in ONE
- : character at a time, without line buffering. In other words when the user
- : presses ONE key, take and process that keypress. I had originally asked if
- : it was possible to use cin or another iostream for this purpose. It would be
- : nice if someone could definitively address this question.
-
- Portably this *cannot* be done.
-
- [snip]
- : If they had finished
- : the chapter they were reading they might have noticed that the get() member
- : function of cin is ALWAYS line buffered! Another way they might have realized
- : that their answer was wrong would have been to COMPILE it.
-
- cin is not ALWAYS line buffered, in fact cin is not buffered at all according
- to the standard:
-
- 27.3.1 Narrow stream objects
-
- istream cin
-
- 1. The object cin controls input from an unbuffered stream buffer associated
- with the object stdin, declared in <cstdio>.
- ...
-
- From the ANSI C std.
-
- ... When opened, the standard input stream is fully buffered if and only if the
- stream can be determined not to refer to an interactive device.
-
- It is the host environment which line buffers.
- In the UNIX environment you can use ioctl() calls to change the
- buffering characteristics of the terminal attached to cin, in other
- environments there may or may not be a mechanism by which you can
- inform the environment that line buffering is not to be performed.
- This is very dependent on the host environment, try a programmers
- newsgroup for the environment you are interested in.
-
- Regards
-
- -A.
- --
- | A.Champion |
-